#hmm test

import irc
import string

class newtest(irc.Protocol):
    def __init__(self):
        irc.Protocol.__init__(self)
        irc.Protocol.connect(self,"irc.efnet.nl", 6667, "be-py")
        #need to check for nick in use
        irc.Protocol.joinc(self,"#liek")
    def dispatch(self, sender, args):
        if args[1] == "PRIVMSG":
            data = args[0].split()
            if data[0].lower() == "!quit":
                if sender.host.lower() in ["c-76-25-4-66.hsd1.co.comcast.net"]:
                    irc.Protocol.disconnect(self,"#liek")
            if data[0].lower() == "!assrape":
                if sender.host.lower() in ["c-76-25-4-66.hsd1.co.comcast.net", "storm.angrycoder.org", "c-69-246-166-145.hsd1.fl.comcast.net"]:
                    try: name=data[1]
                    except: name = ""
                    if name.lower() != self.nickname.lower():
                        irc.Protocol.kick(self,args[2],name,"assraped %s with a spork" % name)
                    else: 
                        irc.Protocol.kick(self,args[2],sender.nick,"assraped")
            if data[0].lower() == "!op":
                try: name = data[1]
                except: name = ""
                if sender.host.lower() in ["c-76-25-4-66.hsd1.co.comcast.net", "storm.angrycoder.org", "c-69-246-166-145.hsd1.fl.comcast.net"]:
                    irc.Protocol.send(self,"MODE %s +o %s" % (args[2], (name or sender.nick)))
            if data[0].lower() == "!wz":
                irc.Protocol.sendmessage(self, args[2], "place holder for weather")
        elif args[1] == "KICK":
            if args[3].lower() == self.nickname.lower():
                irc.Protocol.joinc(self,args[2])
        irc.Protocol.dispatch(self, sender,args)

from commandhandler import CommandHandler

class bot(irc.Protocol):
    def __init__(self):
        irc.Protocol.__init__(self)
        irc.Protocol.connect(self,"irc.efnet.nl", 6667, "sloat-py")
        irc.Protocol.joinc(self,"#liek")
        
        self.cmd = CommandHandler(self)

    def dispatch(self, sender, args):
        self.cmd.dispatch(sender, args)
        irc.Protocol.dispatch(self, sender,args)

if __name__ == "__main__":
    print "bot starting"
    b = bot().start()
    #moo = newtest().start()
